// subHoliday/IdentityApproval/identityApproval.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    key_value: null,
    result: [],
    uid: getApp().globalData.userInfo.id,
    sid: getApp().globalData.userInfo.school_ID,
    ApproveTeacherList: null,
    loading:false,
  },
  // 获取审批列表
  async getApproveTeacherList(keyword) {
    this.setData({
      loading:true
    })
    let params = {
      uid: this.data.uid,
      sid: this.data.sid
    }
    if (keyword) {
      params.keyword = keyword
    }
    try {
      const json = await getApp().$axios("/getApproveTeacherList", "POST", params)
      if (json.status !== 200) {
        wx.showToast({
          title: '获取列表出错',
          icon: 'none'
        })
        return
      }
      this.setData({
        ApproveTeacherList: json.data,
        loading:false
      })
    } catch (error) {
      wx.showToast({
        title: error.msg,
        icon: 'error'
      })
    }
  },
  onChange(e) {
    this.setData({
      result: e.detail,
    });
  },
  onSearch(e) {
    this.setData({
      key_value: e.detail
    })
    this.getApproveTeacherList(e.detail)
  },
  // 批量同意
  async agree(){
    wx.showLoading({
      title: '加载中',
    })
    try {
      const json = await getApp().$axios("/approveTeacher","POST",{ids:this.data.result})
      wx.hideLoading()
      if (json.status!==200) {
        wx.showToast({
          title: '审批异常，请重试',
          icon:'none'
        })
        return
      }
      this.getApproveTeacherList()
    } catch (error) {
      wx.showToast({
        title: error.msg,
        icon:'error'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getApproveTeacherList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})